package TCP.test3;
/*
客户端接收后，服务器给出反馈,多线程改进。
 */

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class SeverDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(10002);
        Socket s = ss.accept();

        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
//        BufferedWriter bw=new BufferedWriter(new FileWriter("test3.java"));
//解决名称冲突问题
        int count = 0;
        File file = new File("test3[" + count + "].java");
        while (file.exists()) {
            count++;
            file = new File("test3[" + count + "].java");
        }
        BufferedWriter bw=new BufferedWriter(new FileWriter(file));

        String line;
        while ((line = br.readLine()) != null) {
            //判断
//            if ("886".equals(line)){
//                break;
//            }
            bw.write(line);
            bw.newLine();
            bw.flush();
        }

//        System.out.println(22222);
        //给出反馈
        BufferedWriter bw1 = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
        bw1.write("文件上传成功");
        bw1.newLine();
        bw1.flush();

        bw.close();
        ss.close();
    }
}
